package com.shijie.controller.erp;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import tk.mybatis.mapper.entity.Condition;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shijie.component.AppUserService;
import com.shijie.core.Result;
import com.shijie.core.ResultGenerator;
import com.shijie.core.annotation.Log;
import com.shijie.core.annotation.RequiresPermissions;
import com.shijie.core.constants.PnConstant.BusinessType;
import com.shijie.domain.entity.UserComments;
import com.shijie.service.UserCommentsService;

/*
 *  @author: smart boy
 *  @date: 2018-08-06
 */
@RestController
@RequestMapping("/erp/comments")
public class UserCommentsController {

    @Resource
    private UserCommentsService userCommentsService;

    @Resource
    private AppUserService appUserService;

    @RequiresPermissions(value={"users:comments:list"})
    @GetMapping
    public Result list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,String q) {
        PageHelper.startPage(page, pageSize);
        Condition condition = new Condition(UserComments.class);
        if(!StringUtils.isEmpty(q)){
        	 condition.createCriteria().andLike("fromName", "%"+q+"%"); 	
        }
        List<UserComments> list = userCommentsService.selectByCondition(condition);
        PageInfo<UserComments> pageInfo = new PageInfo<>(list);
        return ResultGenerator.success(pageInfo);
    }

    @RequiresPermissions(value={"users:comments:delete"})
    @Log(title = "留言管理", action = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        userCommentsService.deleteById(id);
        return ResultGenerator.success();
    }
}

